function coeffout = coefftran(coeffin,direction)
% If direction==0, this takes unbounded log-transformed coefficients and
% puts them in their original form.
% If direction==1, this takes bounded un-tranformed coefficients and
% transforms them into the unbounded log-transformed form.

% initial(1)  %muT
% initial(2)  %sdT
% initial(3)  %rho
% initial(4)  %sdf0
% initial(5)  %sdf1
% initial(6)  %muF
% initial(7)  %ftreat
% initial(8)  %fmoni

if direction==0
    coeffout(1)     = coeffin(1);
    coeffout(2)     = exp(coeffin(2));
    coeffout(3)     = (2/(exp(-coeffin(3)) + 1)) - 1;
    coeffout(4)     = exp(coeffin(4));
    coeffout(5)     = exp(coeffin(5));    
    coeffout(6)     = coeffin(6);
    coeffout(7)     = coeffin(7);
    coeffout(8)     = coeffin(8);
    
elseif direction==1
    coeffout(1)     = coeffin(1);
    coeffout(2)     = log(coeffin(2));
    coeffout(3)     = -log( (1-coeffin(3))/(coeffin(3)+1));
    coeffout(4)     = log(coeffin(4));
    coeffout(5)     = log(coeffin(5));
    coeffout(6)     = coeffin(6);
    coeffout(7)     = coeffin(7);
    coeffout(8)     = coeffin(8);
end
